package org.openrisk.listeners;

import java.util.Date;

import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import org.openrisk.domain.Base;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseListener {
	
	private static final Logger log = LoggerFactory.getLogger(BaseListener.class);
	
	@PrePersist
	public void prePersist(Base base) {
		log.info("BaseListener.PrePersist and base instanceof " +
				base.getClass().getSimpleName() +
				", fields: " +
				base);
		base.setCreationDate(new Date());
		// TODO createdBy User
	}
	
	@PostPersist
	public void postPersist(Base base) {
		log.info("BaseListener.PostPersist and base instanceof " +
				base.getClass().getSimpleName() +
				", fields: " +
				base);
	}
	
	@PreUpdate
	public void preUpdate(Base base) {
		log.info("BaseListener.PreUpdate and base instanceof " +
				base.getClass().getSimpleName() +
				", fields: " +
				base);
		base.setChangeDate(new Date());
		// TODO changedBy User
	}
	
	@PostUpdate
	public void postUpdate(Base base) {
		log.info("BaseListener.PostUpdate and base instanceof " +
				base.getClass().getSimpleName() +
				", fields: " +
				base);
	}
	
//	@PreRemove
//	public void preRemove(Base base) {
//		log.info("BaseListener.Remove called on base id: "
//				+ base.getId());
//		base.setRemoveDate(new Date());
//		// TODO removedBy User
//	}
	
}
